package com.wsc.crawler.grabber;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;


import org.apache.http.HttpHost;
import org.apache.log4j.Logger;

import com.wsc.crawler.URLutils.URLBean;
import com.wsc.crawler.init.CrawlerConfig;
import com.wsc.crawler.utils.CheckHost;

public class LocalClient {

	private String host;
	private final CrawlerConfig config;
	private static Logger log = Logger.getLogger(LocalClient.class.getName());
	private URLBean bean;

	/**
	 * @param config
	 */
	public LocalClient(CrawlerConfig config) {
		this.config = config;
	}

	public URLBeanQueue getUrlsFromFroniter() throws UnknownHostException,
			MalformedURLException {

		HttpHost host = config.getFrontierHost();
		log.info("pinging the host " + host.getHostName() + ".");
		if (CheckHost.isReachableTo(host.getHostName())) {
			log.info("pinging the host " + host.getHostName()
					+ " is successfull.");
			log.info("Checking whether " + host.toString() + " is reachable.");
			if (CheckHost.isPortOpen(config.getFrontierHost())) {
				log.info("the host " + host.toString() + " is reachable.");
				URLBeanQueue queue = new URLBeanQueue();
				// code to connect frontier server and get list of urls from it.
				bean = new URLBean();

		 		bean.setOriginalURL(new URL("http://www.google.co.in/"));
			 	queue.enqueue(bean);
				// queue.enqueue(new URL("http://www.indyarocsasks.com"));
				// queue.enqueue(new
				// URL("http://www.weather.com/weather/local/01602?lswe=01602&lwsa=WeatherLocalUndeclared&from=whatwhere"));
				// queue.enqueue(new URL("https://community.worcester.edu"));
				// queue.enqueue(new URL("http://www.worcester.edu"));
				// queue.enqueue(new URL("http://www.msnbc.msn.com/"));
				// queue.enqueue(new URL("http://www.google.com/"));
				// queue.enqueue(new URL("http://slashdot.org/"));
				// queue.enqueue(new URL("http://digg.com/"));
				// queue.enqueue(new
				// URL("http://www.mysql.com/about/legal/licensing/index.html"));
				// queue.enqueue(new URL("http://mysql.com"));
				// queue.enqueue(new URL("http://dev.mysql.com"));
				// queue.enqueue(new
				// URL("http://effectivemysql.com/book/backup-recovery/"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html"));
				// queue.enqueue(new
				// URL("http://effectiveMySQL.com/article/configuring-a-new-hard-drive-for-lvm/"));
				// queue.enqueue(new
				// URL("http://effectiveMySQL.com/article/using-mysql-with-lvm"));
				// queue.enqueue(new
				// URL("http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)"));
				// queue.enqueue(new
				// URL("http://effectiveMySQL.com/article/creating-mysql-backups-using-lvm/"));
				// queue.enqueue(new URL("https://edelivery.oracle.com/"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/mysql-enterprise-backup/3.7/en/mysqlbackup.backup.html"));
				// queue.enqueue(new
				// URL("http://www.percona.com/downloads/XtraBackup/"));
				// queue.enqueue(new
				// URL("http://www.percona.com/docs/wiki/percona-xtrabackup:xtrabackup:start"));
				// queue.enqueue(new URL("http://www.mydumper.org/"));
				// queue.enqueue(new
				// URL("http://www.zmanda.com/backup-mysql.html"));
				// queue.enqueue(new
				// URL("http://effectiveMySQL.com/article/real-life-disasters"));
				// queue.enqueue(new
				// URL("http://ronaldbradford.com/blog/never-let-your-binlog-directory-fill-up-2009-07-15/"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html"));
				// queue.enqueue(new
				// URL("http://www.percona.com/software/percona-toolkit/"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.5/en/replication-options-table.html"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.5/en/replication-rbr-safe-unsafe.html"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html"));
				// queue.enqueue(new
				// URL("http://www.percona.com/doc/percona-xtrabackup/innobackupex/replication_ibk.html"));
				// queue.enqueue(new URL("http://mysqlsandbox.net/"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.6/en/mysql-nutshell.html"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.6/en/news-5-6-x.html"));
				// queue.enqueue(new
				// URL("http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html"));
				// queue.enqueue(new
				// URL("http://ronaldbradford.com/blog/checked-your-mysql-recovery-process-recently-2010-02-15/"));
				// queue.enqueue(new URL("http://www.chriscalender.com/?p=49"));
				bean = new URLBean();
				queue.enqueue(bean.setOriginalURL(new
				 URL("http://dev.mysql.com/doc/refman/5.5/en/replication-options-slave.html#sysvar_sync_relay_log_info")));
				bean = new URLBean();
				queue.enqueue(bean.setOriginalURL(new URL("http://www.pythian.com/")));
				bean = new URLBean();
				queue.enqueue(bean.setOriginalURL(new URL(
						"http://www.bluegecko.net/gfgggg tyhrt ht/")));
				bean = new URLBean();
				queue.enqueue(bean.setOriginalURL(new URL(
						"http://palominodb.com/")));
				bean = new URLBean();
				queue.enqueue(bean.setOriginalURL(new URL(
						"http://effectivemysql.com/")));
 				bean = new URLBean();
 				queue.enqueue(bean.setOriginalURL(new URL(
 					"http://www.continuent.com/")));
 				bean = new URLBean();
 	 			queue.enqueue(bean.setOriginalURL(new URL(
 	 					"http://www.worldbackupday.com/")));
				bean = new URLBean();
			 	queue.enqueue(bean.setOriginalURL(new URL(
		 				"http://www.ngs.noaa.gov/PUBS_LIB/FundSPCSys.pdf")));

				return queue;
			} else {
				log.warn("Frontier port is not up :" + host.toURI());
			}
		}
		return null;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

}
